Array.prototype.indexOf = function(val) {
  for (var i = 0; i < this.length; i++) {
    if (this[i] == val) return i;
  }
  return -1;
};

Array.prototype.remove = function(val) {
  var index = this.indexOf(val);
  if (index > -1) {
    this.splice(index, 1);
  }
};

function fnIsChecked(obj){
  //判断是否有check属性
  var temp;
  if(obj.attributes.checked){
    temp = obj.attributes.checked.value;
  }else{
    temp="";
  }
  //取得当前input  value属性值
  var values = obj.attributes.value.value;
  var tempData = values.split(":");
  var functionPermissID = tempData[0]+":"+tempData[1];
  var myselectedData = $("#selectedData").val();
  var selectedData = [];
  if(myselectedData!=""){
    if(myselectedData.indexOf("[") != -1 )
    {
      var myData = eval('(' + myselectedData + ')');
      for(var i=0;i<myData.length;i++){
        selectedData.push(myData[i]);
      }
      selectedData = _.uniq(selectedData);
    }else{
      var arryData = myselectedData.split(",");
      for(var i=0;i<arryData.length;i++){
        selectedData.push(arryData[i]);
      }
      selectedData = _.uniq(selectedData);
    }
  }
  if( temp == "checked" ) {
    obj.removeAttribute('checked');
    selectedData.remove(functionPermissID);
    $("#selectedData").val(JSON.stringify(selectedData))
  }
  else {
    obj.setAttribute('checked', 'checked');
    selectedData.push(functionPermissID);
    $("#selectedData").val(JSON.stringify(selectedData));
  }
}
